From: Yehuda Katz Date: Thu, 1 May 2014 04:38:45 +0000 (-0700) Subject: Move package mapping to Source X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~1099 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=21598204f3f04624854068d2e48de3156c03f08d;p=cargo.git Move package mapping to Source --- diff --git a/src/cargo/core/source.rs b/src/cargo/core/source.rs index a0c49d6e0..1b5edaefc 100644 --- a/src/cargo/core/source.rs +++ b/src/cargo/core/source.rs @@ -1,25 +1,7 @@ use std::fmt; -use core::NameVer; +use core::{NameVer,Package}; use CargoResult; -#[deriving(Clone,Eq)] -pub struct PackagePath { - name: NameVer, - path: Path -} - -impl fmt::Show for PackagePath { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f.buf, "{} at {}", self.name, self.path.display()) - } -} - -impl PackagePath { - pub fn new(name: NameVer, path: Path) -> PackagePath { - PackagePath { name: name, path: path } - } -} - /** * A Source finds and downloads remote packages based on names and * versions. @@ -44,7 +26,7 @@ pub trait Source { * The download method fetches the full package for each name and * version specified. */ - fn download(&self, packages: Vec) -> CargoResult<()>; + fn download(&self, packages: &[NameVer]) -> CargoResult<()>; /** * The get method returns the Path of each specified package on the @@ -52,5 +34,5 @@ pub trait Source { * and that the packages are already locally available on the file * system. */ - fn get(&self, packages: Vec) -> CargoResult>; + fn get(&self, packages: Vec) -> CargoResult>; } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index dab23c4cc..20e3c8aa2 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -26,6 +26,8 @@ use util::config; use util::config::{all_configs,ConfigValue}; use cargo_read_manifest = ops::cargo_read_manifest::read_manifest; use core::Package; +use core::source::Source; +use sources::path::PathSource; use {CargoError,ToCargoError,CargoResult}; #[deriving(Decodable)] @@ -46,20 +48,13 @@ pub fn compile() -> CargoResult<()> { let paths = match config_paths.get_value() { &config::String(_) => return Err(CargoError::new(~"The path was configured as a String instead of a List", 1)), - &config::List(ref list) => list + &config::List(ref list) => list.iter().map(|path| Path::new(path.as_slice())).collect() }; - println!("Paths: {}: {}", paths.len(), paths); - - let packages: Vec = paths.iter().filter_map(|path| { - let joined = Path::new(path.as_slice()).join("Cargo.toml"); - let manifest = cargo_read_manifest(joined.as_str().unwrap()); - - match manifest { - Ok(ref manifest) => Some(Package::from_manifest(manifest)), - Err(_) => None - } - }).collect(); + let source = PathSource::new(paths); + let names = try!(source.list()); + try!(source.download(names.as_slice())); + let packages = try!(source.get(names)); println!("Packages: {}", packages); Ok(()) diff --git a/src/cargo/sources/mod.rs b/src/cargo/sources/mod.rs index 1fb8cc55c..4da978923 100644 --- a/src/cargo/sources/mod.rs +++ b/src/cargo/sources/mod.rs @@ -1 +1 @@ -mod path; +pub mod path; diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 256620bad..f6045b8b4 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -1,9 +1,10 @@ -use core::source::{Source,PackagePath}; -use core::NameVer; +use core::{NameVer,Package}; +use core::source::Source; +use core::manifest::Manifest; use CargoResult; -use ops::cargo_read_manifest::read_manifest; +use cargo_read_manifest = ops::cargo_read_manifest::read_manifest; -struct PathSource { +pub struct PathSource { paths: Vec } @@ -27,23 +28,29 @@ impl Source for PathSource { fn update(&self) -> CargoResult<()> { Ok(()) } fn list(&self) -> CargoResult> { - self.map(|path| { - let manifest = try!(read_manifest(path.as_str().unwrap())); - Ok(manifest.get_name_ver()) - }) + Ok(self.paths.iter().filter_map(|path| { + match read_manifest(path) { + Ok(ref manifest) => Some(manifest.get_name_ver()), + Err(_) => None + } + }).collect()) } - fn download(&self, name_ver: Vec) -> CargoResult<()>{ + fn download(&self, name_ver: &[NameVer]) -> CargoResult<()>{ Ok(()) } - fn get(&self, packages: Vec) -> CargoResult> { - self.map(|path| { - let manifest = try!(read_manifest(path.as_str().unwrap())); - let name_ver = manifest.get_name_ver(); - let path = manifest.get_path(); - - Ok(PackagePath::new(name_ver, path)) - }) + fn get(&self, packages: Vec) -> CargoResult> { + Ok(self.paths.iter().filter_map(|path| { + match read_manifest(path) { + Ok(ref manifest) => Some(Package::from_manifest(manifest)), + Err(_) => None + } + }).collect()) } } + +fn read_manifest(path: &Path) -> CargoResult { + let joined = path.join("Cargo.toml"); + cargo_read_manifest(joined.as_str().unwrap()) +}